package com.example.fragmentdemo_729;

import android.content.Context;
import android.content.SharedPreferences;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;

public abstract class BaseFragment extends Fragment {
    private final String KEY_SESSION_ID = "session";
    private final String KEY_USERNAME = "name";
    private final int MODE  = Context.MODE_PRIVATE;

    protected Context context;
    private SharedPreferences sharedPreferences;
    private final String FILE = "login";

    @Override
    public void onAttach(@NonNull Context context) {
        super.onAttach(context);
        this.context = context;
        sharedPreferences = context.getSharedPreferences(FILE, Context.MODE_PRIVATE);
    }

    protected String getSessionId(){
        return sharedPreferences.getString(KEY_SESSION_ID,"");
    }

    protected String getUserName(){
        return sharedPreferences.getString(KEY_USERNAME,"");
    }
}
